package com.sphd.emanu.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;

import java.util.List;

/**
 * @Author Hu
 * @Time 2017/4/1 .15:24.
 * @Email 87683202@qq.com
 */
public class MyViewPagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;
    private String[] string;
    private  Context context;
    private FragmentManager fm;
    public MyViewPagerAdapter(Context context, FragmentManager fm, List<Fragment> fragments, String[] strings) {
        super(fm);
        this.fm=fm;
        this.context=context;
        this.fragments = fragments;
       this.string=strings;
    }


    @Override
    public int getCount() {
        return fragments.size();
    }


    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return string[position];
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        Fragment fragment = (Fragment)super.instantiateItem(container,position);
        fm.beginTransaction().show(fragment).commit();
        return fragment;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        Fragment fragment = fragments.get(position);
        fm.beginTransaction().hide(fragment).commit();
    }
}
